package com.oriental.manage.controller.reserve.business;

import com.oriental.manage.core.exception.BusiException;
import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.service.reserve.ReportAdjustmentService;
import com.oriental.reserve.model.trans.AdjustmentDetailDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Author: Yang xp
 * Date: 2017/3/2
 * Time: 10:02
 * Desc：备付金调整报表
 */
@Controller
@Slf4j
@RequestMapping("/reserve/report/adjustment")
public class ReserveReportAdjustmentController {

    @Autowired
    private ReportAdjustmentService reportAdjustmentService;

    @RequestMapping("/init")
    public String init(){
        return "reserve/report/searchAdjustmentDetail";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "reserve/report/addAdjustmentDetail";
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(){
        return "reserve/report/updateAdjustmentDetail";
    }

    @RequestMapping("/search")
    @ResponseBody
    public ResponseDTO<Pagination<AdjustmentDetailDto>> search(@RequestBody Pagination<AdjustmentDetailDto> pagination){
        ResponseDTO<Pagination<AdjustmentDetailDto>> responseDTO = new ResponseDTO<>();
        try {
            log.info("调整信息请求参数：{}",pagination);
            reportAdjustmentService.queryAdjustment(responseDTO,pagination,pagination.getQueryBean());
        }catch (Exception e){
            log.error("查询调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("调整信息查询失败");
        }
        return responseDTO;
    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseDTO<String> create(@RequestBody AdjustmentDetailDto adjustmentDetailDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("新增调整信息请求参数：{}",adjustmentDetailDto);
            reportAdjustmentService.createAdjustment(responseDTO,adjustmentDetailDto);
        }catch (Exception e){
            log.error("新增调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("新增调整信息失败");
        }
        return responseDTO;
    }

    @RequestMapping("/update")
    @ResponseBody
    public ResponseDTO<String> update(@RequestBody AdjustmentDetailDto adjustmentDetailDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("修改调整信息请求参数：{}",adjustmentDetailDto);
            reportAdjustmentService.updateAdjustment(responseDTO,adjustmentDetailDto);
        }catch (Exception e){
            log.error("修改调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("修改调整信息失败");
        }
        return responseDTO;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseDTO<String> delete(@RequestBody AdjustmentDetailDto adjustmentDetailDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("删除调整信息请求参数：{}",adjustmentDetailDto);
            reportAdjustmentService.deleteAdjustment(responseDTO,adjustmentDetailDto);
        }catch (Exception e){
            log.error("删除调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("删除调整信息失败");
        }
        return responseDTO;
    }
    @RequestMapping("/review/pass")
    @ResponseBody
    public ResponseDTO<String> reviewPass(@RequestBody List<AdjustmentDetailDto> adjustmentDetailDtoList){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("审核通过调整信息请求参数：{}",adjustmentDetailDtoList);
            reportAdjustmentService.reviewPass(responseDTO,adjustmentDetailDtoList);
        }catch (BusiException e){
            log.error("审核通过调整110数据异常:",e);
            responseDTO.setCode(e.getCode());
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getDesc());
        }catch (Exception e){
            log.error("审核通过调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("审核通过调整信息失败");
        }
        return responseDTO;
    }


    @RequestMapping("/review/reject")
    @ResponseBody
    public ResponseDTO<String> reviewReject(@RequestBody List<AdjustmentDetailDto> adjustmentDetailDtoList){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("审核拒绝调整信息请求参数：{}",adjustmentDetailDtoList);
            reportAdjustmentService.reviewFail(responseDTO,adjustmentDetailDtoList);
        }catch (BusiException e){
            log.error("审核通过调整110数据异常:",e);
            responseDTO.setCode(e.getCode());
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getDesc());
        }catch (Exception e){
            log.error("审核拒绝调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("审核拒绝调整信息失败");
        }
        return responseDTO;
    }

    @RequestMapping("/review/back")
    @ResponseBody
    public ResponseDTO<String> reviewBack(@RequestBody List<AdjustmentDetailDto> adjustmentDetailDtoList){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("审核回退调整信息请求参数：{}",adjustmentDetailDtoList);
            reportAdjustmentService.reviewBack(responseDTO,adjustmentDetailDtoList);
        }catch (BusiException e){
            log.error("审核通过调整110数据异常:",e);
            responseDTO.setCode(e.getCode());
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getDesc());
        }catch (Exception e){
            log.error("审核回退调整数据异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("审核回退调整信息失败");
        }
        return responseDTO;
    }


}
